//
//  XYTableView.m
//  LabHelper
//
//  Created by 找汽配 on 2017/5/31.
//  Copyright © 2017年 XiangYun. All rights reserved.
//

#import "XYImageScrollViewCell.h"
#import "XYImageScrollViewModel.h"

@interface XYImageScrollViewCell () <XYImageScrollViewModelDelegate>

@property (weak, nonatomic) IBOutlet UIImageView * imageView;

@property (nonatomic, weak) XYImageScrollViewModel * model;

@end

@implementation XYImageScrollViewCell

+ (instancetype)cell {
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] firstObject];
}

- (void)reloadCell {
    if (self.model.image) {
        self.imageView.image = self.model.image;
    }
    else {
        self.imageView.image = self.defaultImage;
        [self.model reloadImage];
    }
}

- (IBAction)buttonTouchUpInside {
    if (self.delegate && [self.delegate respondsToSelector:@selector(imageScrollViewCellDidSelectWithModel:)]) {
        [self.delegate imageScrollViewCellDidSelectWithModel:self.model];
    }
}

#pragma mark - Setter

- (void)setModel:(XYImageScrollViewModel *)model {
    _model = model;
    model.delegate = self;
    
    [self reloadCell];
}

#pragma mark - XYImageScrollViewModelDelegate

- (void)imageScrollViewModelDidUpdate {
    [self reloadCell];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
